package com.king.designpatterns.七大原则.单一职责;

/**
 * 用户管理类
 * @author king
 * @date 2020/9/28 14:19
 */
public class UserManager {
    private UserDao userDao = new UserDao();

    /**
     * 验证用户名和密码
     */
    public boolean checkUser(String name, String pass){
        boolean flag = false;
        User user = userDao.getUserByName(name);
        if(null != user && pass.equals(user.getUserpass())){
            flag = true;
        }
        return flag;
    }

    /**
     * 注册新用户
     */
    public void registUser(User user){
        if (null != userDao.getUserByName(user.getUsername())){
            System.out.println("此用户名已注册, 请换一个新的用户名");
            return;
        }

        if (userDao.addUser(user)){
            System.out.println("新用户注册成功");
        }else{
            System.out.println("新用户注册失败");
        }
    }

}
